<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>成绩统计</title>
	</head>
	<body>
		<input name="aa" type="button" value="确定" onclick="tongji( )"  />
		<script type="text/javascript">
			function tongji(){
				var numb = prompt("请输入考试科目数量"," ");
				var num = parseInt(numb);
				if(num<=0){
					alert("输入的不是数字");
					return;
				}
				var sum = 0;
				for (var i = 0;i<num;i++) {
					var socal = prompt("请输入" + (i+1) + "门科目成绩：" ,"");
					if(socal<=0){
						alert("成绩不能是负数！");
						return;
					}
					sum+=parseInt(socal);
				}
				alert(num + "门科目的总成绩是：" + sum);
			}
			
		</script>
	</body>
</html>
